<?php
include $this->Render('header.php');
?>
<link rel="stylesheet" type="text/css" href="<?php echo BASE_STYLE;?>/css/admin.css" />
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/dyhl.linkpage.js"></script>
<script type="text/javascript" src="<?php echo BASE_STYLE;?>/js/common.js"></script>
<style type="text/css">
	.tongrong-box {
		padding:20px 30px 30px  30px;
	}
</style>
<div class="tongrong-box" style="width:680px;">
	<form class="login-box-form J-ajaxForm" action="<?php echo $this->id > 0 ? '/branch/update/option/save/' : '/branch/save/option/save/';?>" method="post" autocomplete="off">
	<div class="tongrong-box-main">
    	<table width="100%" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="90px" height="30">网点编号：</td>
                <td>
                	<input name="br_code" type="text" id="br_code" readonly size="35" style="background: rgb(230, 230, 230)" value="<?php echo $this->data['br_code'];?>" />                </td>
            </tr>
            <tr>
            	<td height="30">网点名称：</td>
                <td>
                	<input name="br_name" type="text" id="br_name" size="35" value="<?php echo $this->data['br_name'];?>" />                </td>
            </tr>
            <tr>
              <td height="30">收款单位：</td>
              <td><input name="br_payee" type="text" id="br_payee" size="35" value="<?php echo $this->data['br_payee'];?>" /></td>
            </tr>
            <tr>
              <td height="30">开户银行：</td>
              <td><input name="br_acc_bank" type="text" id="br_acc_bank" size="35" value="<?php echo $this->data['br_acc_bank'];?>" /></td>
            </tr>
            <tr>
              <td height="30">开户账号：</td>
              <td><input name="br_acc_no" type="text" id="br_acc_no" size="35" value="<?php echo $this->data['br_acc_no'];?>" /></td>
            </tr>
            <tr>
              <td height="30">最大公司利率：</td>
              <td><input name="br_max_rate" type="text" id="br_max_rate" size="10" value="<?php echo $this->data['br_max_rate'];?>" />&nbsp;
              %</td>
            </tr>
            <tr>
            	<td height="30">所属大区：</td>
                <td>
                	<select class="J-br-rgid" name="br_rgid">
                    	<option value="0">请选择</option>
                    </select>                </td>
            </tr>
            <tr>
            	<td height="30">所属拓展经理：</td>
                <td>
                	<select class="J-br-uid" name="br_uid">
                    	<option value="0">请选择</option>
                    </select>                </td>
            </tr>
            
            <script type="text/javascript">
				window.uDpType = '<?php echo $this->data['br_rgid'];?>';
				window.uid = '<?php echo $this->data['br_uid'];?>';
            	$(document).ready(function(e) {
                    getRegion(uDpType);
					
					$(".J-br-rgid").on('change',function(){
						var bid = $(this).val();
						getBruid(bid,0);	
					});
					
					//编辑
					<?php if(!empty($this->data['br_uid'])){?>
						getBruid(uDpType,uid);
					<?php }?>
                });
				
				
				function getRegion(rgid){
					$.post('/public/ajax/option/region/',{"list":'br'},function(data){
						if(data){
							var html='<option value="0">请选择</option>';
							for(var i =0; i < data.length; i++){
								if(rgid == data[i]['rg_id']){
									html+='<option selected value="'+data[i]['rg_id']+'">'+data[i]['rg_name']+'</option>';
								}else{
									html+='<option value="'+data[i]['rg_id']+'">'+data[i]['rg_name']+'</option>';
								}	
							}
							
							$(".J-br-rgid").html(html);
						}
						
					},'json');	
				}
				
				function getBruid(rid,uid){
					$.post('/public/ajax/option/get_salesman/',{"rg_id":rid},function(data){
						if(data){
							var html='<option value="0">请选择</option>';
							for(var i =0; i < data.length; i++){
								if(uid == data[i]['u_id']){
									html+='<option selected value="'+data[i]['u_id']+'">'+data[i]['u_realname']+'</option>';
								}else{
									html+='<option value="'+data[i]['u_id']+'">'+data[i]['u_realname']+'</option>';
								}	
							}
							
							$(".J-br-uid").html(html);
						}
						
					},'json');	
				}
            </script>
            
            <tr>
            	<td height="30">所在地省市：</td>
                <td id="areas">
                	<select id="province" name="br_province" class="mr15" ></select>
                    <select id="city" name="br_city"></select>
                    <input id="test" type="text" style="visibility:hidden;width:0;" value="" alt="请选择完整地区信息！"><label></label>                </td>
            </tr>
            <script type="text/javascript">
            	$(document).ready(function(e) {
            	<?php if(empty($this->data['br_code'])){?>
            		var province = '浙江省';
            		var city = '杭州市';
            		$.post('/public/ajax/option/branchnum/',{'province':province,'city':city},function(data){
            			$("#br_code").val(data)
						},'html');
            		$("select#city").change(function(){
            			province = document.getElementById("province").value;
            		    city = document.getElementById("city").value;
            		    $.post('/public/ajax/option/branchnum/',{'province':province,'city':city},function(data){
            		    	$("#br_code").val(data)
						},'html');
            		});
            		<?php }?>
			});
            </script>
            <tr>
            	<td height="30">网点业务模式：</td>
                <td>
                	<label>
                    	<input type="radio" name="br_model" <?php echo $this->data['br_model']=='普通' ? 'checked' :'';?> value="普通" style="vertical-align:sub;" />&nbsp;普通模式                    </label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label>
                    	<input type="radio" name="br_model" <?php echo $this->data['br_model']=='预审' ? 'checked' :'';?> value="预审" style="vertical-align:sub;" />&nbsp;预审模式                    </label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label>
                    	<input type="radio" name="br_model" <?php echo $this->data['br_model']=='超级预审' ? 'checked' :'';?> value="超级预审" style="vertical-align:sub;" />&nbsp;超级预审模式                    </label>                </td>
            </tr>
            <tr>
            	<td height="30" valign="top">授权银行：</td>
                <td>
                	<style type="text/css">
                    	/* 选择银行列表 */
						.bank-list {
							max-height:250px; overflow:auto; margin-top:5px; font-size:12px; border:1px solid #e1e1e1; padding:10px 15px; height:100px; overflow-y:scroll; overflow-x:hidden;
						}
						
						.bank-list li {
							padding:3px 0;
						}
						
						.bank-list li input {
							vertical-align:sub;
						}
                    </style>
                    
                	<ul class="bank-list">
                        <li>
                            <input type="checkbox" class="checkAll" rel="bank" value="1" /> 全选                        </li>
						<?php
							if(!empty($this->bank)) foreach($this->bank as $k=>$v){
								$select = in_array($v['bk_id'], empty($this->data['br_bank_arr']) ? array() : $this->data['br_bank_arr']) ? ' checked="checked"' : '';
						?>
                        <li>
                            <label>
							<input name="br_bank[]" type="checkbox" class="child_bank" value="<?php echo $v['bk_id'];?>"<?php echo $select;?> />&nbsp; 
                            <?php echo $v['bk_name'];?>							</label>
                        </li>
						<?php
							}
						?>
                    </ul>                </td>
            </tr>
        </table>
    </div>
    <div class="luru-box-btn mt30">
		<input type="hidden" name="option" value="save" />
		<input type="hidden" name="id" value="<?php echo $this->id;?>" />
    	<input class="btn-submit-blue fn-left mr15 J-submit" type="submit" value="提交" />
        <a class="a-btn-close J-a-btn-close" href="javascript:;">关闭</a>
    </div>
	</form>
</div>

<script>
	$("#areas").Linkage({ url:"/public/ajax/?option=city",selected:['<?php echo empty($this->data['br_province']) ? '浙江省' : $this->data['br_province'];?>','<?php echo empty($this->data['br_city']) ? '杭州市' : $this->data['br_city'];?>',''],callback:function(data){
		var text = new Array();
		var value = new Array();
		for(i in data[0]){
		  if(data[0][i]!=0){
			text.push(data[1][i]);
			value.push(data[0][i]);
		  }
		}
		$("#test").val(value.join(','));
		FireEvent(document.getElementById("test"),"change");
	}});
	
	//关闭弹出
	$(".J-a-btn-close").on('click',function(){
		
		var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
		parent.Ext.getCmp(winElement.id).close();
		
	});
	
	$(document).ready(function(e) {
        $(".J-submit").on('click',function(){
			$(this).dyhlForm({
				beforefunction:submitChk,
				nofunction:function(){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask();
				},
				sucessfunction:function(data){
					$(".J-submit").prop('disabled',false);
					Ext.getBody().unmask();
					if(data['success']){
						Ext.Msg.alert('提示','提交成功',function(){
							window.parent.App.store.reload();
							var winElement = parent.Ext.fly(window.frameElement).up('div.x-window');
							parent.Ext.getCmp(winElement.id).close();
						});
					}else{
						Ext.Msg.alert('提示',data['msg']);
					}
				}	
			});	
		});
    });
	
	//表单验证
	function submitChk(){
		if($("#br_code").val() == ''){
			Ext.Msg.alert('提示','网点编号不能为空!');	
			return false;
		}
		
		if($("#br_name").val() == ''){
			Ext.Msg.alert('提示','网点名称不能为空!');	
			return false;
		}
		
		$(".J-submit").prop('disabled',true);
		Ext.getBody().mask("数据提交中，请稍等");
			
	}
	
</script>

<?php include $this->Render('footer.php'); ?>